"""
应用配置管理
"""
from pydantic_settings import BaseSettings, SettingsConfigDict
from pathlib import Path


class Settings(BaseSettings):
    """应用配置类"""
    
    # OpenAI API 配置
    OPENAI_API_KEY: str
    OPENAI_BASE_URL: str = "https://api.openai.com/v1"
    
    # 模型配置
    EMBEDDING_MODEL: str = "text-embedding-3-small"
    CHAT_MODEL: str = "gpt-4o-mini"
    
    # 处理配置
    CHUNK_SIZE: int = 500
    TOP_K: int = 3
    
    # 存储配置
    DATA_DIR: str = "data"
    
    # 日志配置
    LOG_LEVEL: str = "INFO"
    
    model_config = SettingsConfigDict(
        env_file=".env",
        env_file_encoding="utf-8",
        case_sensitive=True
    )
    
    @property
    def uploads_dir(self) -> Path:
        """上传文件目录"""
        return Path(self.DATA_DIR) / "uploads"
    
    @property
    def knowledge_base_path(self) -> Path:
        """知识库文件路径"""
        return Path(self.DATA_DIR) / "knowledge_base.json"


# 全局配置实例
settings = Settings()

